package com.yhw.srb.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yhw.srb.core.pojo.entity.UserLoginRecord;
import com.yhw.srb.core.mapper.UserLoginRecordMapper;
import com.yhw.srb.core.service.UserLoginRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户登录记录表 服务实现类
 * </p>
 *
 * @author yhw
 * @since 2022-08-29
 */
@Service
public class UserLoginRecordServiceImpl extends ServiceImpl<UserLoginRecordMapper, UserLoginRecord> implements UserLoginRecordService {

    @Override
    public List<UserLoginRecord> listTop50(Long userId) {

        LambdaQueryWrapper<UserLoginRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserLoginRecord::getUserId,userId);
        queryWrapper.orderByDesc(UserLoginRecord::getId);   // 查看登录记录 肯定是要 最近登录的排在前面
        queryWrapper.last("limit 50"); // 前50条记录
        List<UserLoginRecord> list = baseMapper.selectList(queryWrapper);

        return list;
    }
}
